import router from "@/router";
import { usePermissionStoreHook } from "@/store/modules/permission";

import NProgress from "nprogress";
import "nprogress/nprogress.css";

NProgress.configure({ showSpinner: false }); // 进度条

const permissionStore = usePermissionStoreHook();

router.beforeEach(async (to, from, next) => {
  NProgress.start();
  // 未匹配到任何路由，跳转404
  if (to.matched.length === 0) {
    from.name ? next({ name: from.name }) : next("/404");
  } else {
    next();
  }
});

router.afterEach(() => {
  NProgress.done();
});
